package com.szh.a0522_shenzhihao.DBHelper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyOpenHelper extends SQLiteOpenHelper {
    public MyOpenHelper(@Nullable Context context) {
        super(context, "book.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table book(_id integer primary key autoincrement,name varchar(10) not null," +
                "author varchar(10),count varchar(10))";
        db.execSQL(sql);
        String sql2 = "insert into book(name,author,count)values(?,?,?)";
        db.execSQL(sql2, new Object[]{"霍乱时期的爱情", "加西亚·马尔克斯","100"});
        db.execSQL(sql2, new Object[]{"白夜行", "东野圭吾","200"});
        db.execSQL(sql2, new Object[]{"西游记", "吴承恩","300"});
        db.execSQL(sql2, new Object[]{"水浒传", "施耐庵","400"});
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
